package com.example.homeworkmutualevaluation.Dao;

import com.example.homeworkmutualevaluation.Entity.Discuss;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface DiscussDao extends JpaRepository<Discuss, String> {
    @Query(value = "SELECT * FROM discuss WHERE `homeworkid`=?1 ORDER BY datetime DESC", nativeQuery = true)
    List<Discuss> findAllByHomeworkid(int homeworkid);
    @Transactional
    @Modifying
    @Query(value = "INSERT INTO discuss(`id`, `sphone`, `homeworkid`, `content`) VALUES (?1, ?2, ?3, ?4)", nativeQuery = true)
    int insert(String id, String sphone, int homeworkid, String content);
    @Transactional
    @Modifying
    @Query(value = "DELETE FROM discuss WHERE `id`=?1", nativeQuery = true)
    int delete(String id);
}
